<template>
  <el-dialog
    :title="!dataForm.id ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
    <el-form-item label="商家ID" prop="sellerId">
      <el-input v-model="dataForm.sellerId" placeholder="商家ID"></el-input>
    </el-form-item>
    <el-form-item label="用户ID" prop="userId">
      <el-input v-model="dataForm.userId" placeholder="用户ID"></el-input>
    </el-form-item>
    <el-form-item label="名字" prop="name">
      <el-input v-model="dataForm.name" placeholder="名字"></el-input>
    </el-form-item>
    <el-form-item label="地址" prop="address">
      <el-input v-model="dataForm.address" placeholder="地址"></el-input>
    </el-form-item>
    <el-form-item label="联系人" prop="linkName">
      <el-input v-model="dataForm.linkName" placeholder="联系人"></el-input>
    </el-form-item>
    <el-form-item label="联系电话" prop="linkTel">
      <el-input v-model="dataForm.linkTel" placeholder="联系电话"></el-input>
    </el-form-item>
    <el-form-item label="餐馆电话" prop="sellerTel">
      <el-input v-model="dataForm.sellerTel" placeholder="餐馆电话"></el-input>
    </el-form-item>
    <el-form-item label="办理时间" prop="registerTime">
      <el-input v-model="dataForm.registerTime" placeholder="办理时间"></el-input>
    </el-form-item>
    <el-form-item label="开业时间" prop="openTime">
      <el-input v-model="dataForm.openTime" placeholder="开业时间"></el-input>
    </el-form-item>
    <el-form-item label="餐馆政策" prop="policy">
      <el-input v-model="dataForm.policy" placeholder="餐馆政策"></el-input>
    </el-form-item>
    <el-form-item label="餐馆介绍" prop="introduction">
      <el-input v-model="dataForm.introduction" placeholder="餐馆介绍"></el-input>
    </el-form-item>
    <el-form-item label="温馨提示" prop="prompt">
      <el-input v-model="dataForm.prompt" placeholder="温馨提示"></el-input>
    </el-form-item>
    <el-form-item label="餐馆logo" prop="ewmLogo">
      <el-input v-model="dataForm.ewmLogo" placeholder="餐馆logo"></el-input>
    </el-form-item>
    <el-form-item label="身份证正面照" prop="idCardImg1">
      <el-input v-model="dataForm.idCardImg1" placeholder="身份证正面照"></el-input>
    </el-form-item>
    <el-form-item label="身份证反面照" prop="idCardImg2">
      <el-input v-model="dataForm.idCardImg2" placeholder="身份证反面照"></el-input>
    </el-form-item>
    <el-form-item label="服务商编号" prop="serviceProviderNo">
      <el-input v-model="dataForm.serviceProviderNo" placeholder="服务商编号"></el-input>
    </el-form-item>
    <el-form-item label="营业执照" prop="businessLicense">
      <el-input v-model="dataForm.businessLicense" placeholder="营业执照"></el-input>
    </el-form-item>
    <el-form-item label="补充说明" prop="other">
      <el-input v-model="dataForm.other" placeholder="补充说明"></el-input>
    </el-form-item>
    <el-form-item label="1待审核,2通过，3拒绝" prop="status">
      <el-input v-model="dataForm.status" placeholder="1待审核,2通过，3拒绝"></el-input>
    </el-form-item>
    <el-form-item label="申请时间" prop="sqTime">
      <el-input v-model="dataForm.sqTime" placeholder="申请时间"></el-input>
    </el-form-item>
    <el-form-item label="绑定提现人" prop="bdId">
      <el-input v-model="dataForm.bdId" placeholder="绑定提现人"></el-input>
    </el-form-item>
    <el-form-item label="余额支付" prop="yeOpen">
      <el-input v-model="dataForm.yeOpen" placeholder="余额支付"></el-input>
    </el-form-item>
    <el-form-item label="微信支付" prop="wxOpen">
      <el-input v-model="dataForm.wxOpen" placeholder="微信支付"></el-input>
    </el-form-item>
    <el-form-item label="到店支付" prop="ddOpen">
      <el-input v-model="dataForm.ddOpen" placeholder="到店支付"></el-input>
    </el-form-item>
    <el-form-item label="经度" prop="lnt">
      <el-input v-model="dataForm.lnt" placeholder="经度"></el-input>
    </el-form-item>
    <el-form-item label="纬度" prop="lat">
      <el-input v-model="dataForm.lat" placeholder="纬度"></el-input>
    </el-form-item>
    <el-form-item label="预定提醒" prop="reserveRemind">
      <el-input v-model="dataForm.reserveRemind" placeholder="预定提醒"></el-input>
    </el-form-item>
    <el-form-item label="餐馆标签" prop="tags">
      <el-input v-model="dataForm.tags" placeholder="餐馆标签"></el-input>
    </el-form-item>
    <el-form-item label="营业类型" prop="businessType">
      <el-input v-model="dataForm.businessType" placeholder="营业类型"></el-input>
    </el-form-item>
    <el-form-item label="菜系风格" prop="cuisineStyle">
      <el-input v-model="dataForm.cuisineStyle" placeholder="菜系风格"></el-input>
    </el-form-item>
    <el-form-item label="备注" prop="remark">
      <el-input v-model="dataForm.remark" placeholder="备注"></el-input>
    </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()" :disabled="disabledSubmit">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          id: 0,
          sellerId: '',
          userId: '',
          name: '',
          address: '',
          linkName: '',
          linkTel: '',
          sellerTel: '',
          registerTime: '',
          openTime: '',
          policy: '',
          introduction: '',
          prompt: '',
          ewmLogo: '',
          idCardImg1: '',
          idCardImg2: '',
          serviceProviderNo: '',
          businessLicense: '',
          other: '',
          status: '',
          sqTime: '',
          bdId: '',
          yeOpen: '',
          wxOpen: '',
          ddOpen: '',
          lnt: '',
          lat: '',
          reserveRemind: '',
          tags: '',
          businessType: '',
          cuisineStyle: '',
          remark: ''
        },
        dataRule: {
          sellerId: [
            { required: true, message: '商家ID不能为空', trigger: 'blur' }
          ],
          userId: [
            { required: true, message: '用户ID不能为空', trigger: 'blur' }
          ],
          name: [
            { required: true, message: '名字不能为空', trigger: 'blur' }
          ],
          address: [
            { required: true, message: '地址不能为空', trigger: 'blur' }
          ],
          linkName: [
            { required: true, message: '联系人不能为空', trigger: 'blur' }
          ],
          linkTel: [
            { required: true, message: '联系电话不能为空', trigger: 'blur' }
          ],
          sellerTel: [
            { required: true, message: '餐馆电话不能为空', trigger: 'blur' }
          ],
          registerTime: [
            { required: true, message: '办理时间不能为空', trigger: 'blur' }
          ],
          openTime: [
            { required: true, message: '开业时间不能为空', trigger: 'blur' }
          ],
          policy: [
            { required: true, message: '餐馆政策不能为空', trigger: 'blur' }
          ],
          introduction: [
            { required: true, message: '餐馆介绍不能为空', trigger: 'blur' }
          ],
          prompt: [
            { required: true, message: '温馨提示不能为空', trigger: 'blur' }
          ],
          ewmLogo: [
            { required: true, message: '餐馆logo不能为空', trigger: 'blur' }
          ],
          idCardImg1: [
            { required: true, message: '身份证正面照不能为空', trigger: 'blur' }
          ],
          idCardImg2: [
            { required: true, message: '身份证反面照不能为空', trigger: 'blur' }
          ],
          serviceProviderNo: [
            { required: true, message: '服务商编号不能为空', trigger: 'blur' }
          ],
          businessLicense: [
            { required: true, message: '营业执照不能为空', trigger: 'blur' }
          ],
          other: [
            { required: true, message: '补充说明不能为空', trigger: 'blur' }
          ],
          status: [
            { required: true, message: '1待审核,2通过，3拒绝不能为空', trigger: 'blur' }
          ],
          sqTime: [
            { required: true, message: '申请时间不能为空', trigger: 'blur' }
          ],
          bdId: [
            { required: true, message: '绑定提现人不能为空', trigger: 'blur' }
          ],
          yeOpen: [
            { required: true, message: '余额支付不能为空', trigger: 'blur' }
          ],
          wxOpen: [
            { required: true, message: '微信支付不能为空', trigger: 'blur' }
          ],
          ddOpen: [
            { required: true, message: '到店支付不能为空', trigger: 'blur' }
          ],
          lnt: [
            { required: true, message: '经度不能为空', trigger: 'blur' }
          ],
          lat: [
            { required: true, message: '纬度不能为空', trigger: 'blur' }
          ],
          reserveRemind: [
            { required: true, message: '预定提醒不能为空', trigger: 'blur' }
          ],
          tags: [
            { required: true, message: '餐馆标签不能为空', trigger: 'blur' }
          ],
          businessType: [
            { required: true, message: '营业类型不能为空', trigger: 'blur' }
          ],
          cuisineStyle: [
            { required: true, message: '菜系风格不能为空', trigger: 'blur' }
          ],
          remark: [
            { required: true, message: '备注不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.id = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.id) {
            this.$http({
              url: this.$http.adornUrl(`/store/tstoreseller/info/${this.dataForm.id}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.sellerId = data.tStoreSeller.sellerId
                this.dataForm.userId = data.tStoreSeller.userId
                this.dataForm.name = data.tStoreSeller.name
                this.dataForm.address = data.tStoreSeller.address
                this.dataForm.linkName = data.tStoreSeller.linkName
                this.dataForm.linkTel = data.tStoreSeller.linkTel
                this.dataForm.sellerTel = data.tStoreSeller.sellerTel
                this.dataForm.registerTime = data.tStoreSeller.registerTime
                this.dataForm.openTime = data.tStoreSeller.openTime
                this.dataForm.policy = data.tStoreSeller.policy
                this.dataForm.introduction = data.tStoreSeller.introduction
                this.dataForm.prompt = data.tStoreSeller.prompt
                this.dataForm.ewmLogo = data.tStoreSeller.ewmLogo
                this.dataForm.idCardImg1 = data.tStoreSeller.idCardImg1
                this.dataForm.idCardImg2 = data.tStoreSeller.idCardImg2
                this.dataForm.serviceProviderNo = data.tStoreSeller.serviceProviderNo
                this.dataForm.businessLicense = data.tStoreSeller.businessLicense
                this.dataForm.other = data.tStoreSeller.other
                this.dataForm.status = data.tStoreSeller.status
                this.dataForm.sqTime = data.tStoreSeller.sqTime
                this.dataForm.bdId = data.tStoreSeller.bdId
                this.dataForm.yeOpen = data.tStoreSeller.yeOpen
                this.dataForm.wxOpen = data.tStoreSeller.wxOpen
                this.dataForm.ddOpen = data.tStoreSeller.ddOpen
                this.dataForm.lnt = data.tStoreSeller.lnt
                this.dataForm.lat = data.tStoreSeller.lat
                this.dataForm.reserveRemind = data.tStoreSeller.reserveRemind
                this.dataForm.tags = data.tStoreSeller.tags
                this.dataForm.businessType = data.tStoreSeller.businessType
                this.dataForm.cuisineStyle = data.tStoreSeller.cuisineStyle
                this.dataForm.remark = data.tStoreSeller.remark
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/store/tstoreseller/${!this.dataForm.id ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData({
                'id': this.dataForm.id || undefined,
                'sellerId': this.dataForm.sellerId,
                'userId': this.dataForm.userId,
                'name': this.dataForm.name,
                'address': this.dataForm.address,
                'linkName': this.dataForm.linkName,
                'linkTel': this.dataForm.linkTel,
                'sellerTel': this.dataForm.sellerTel,
                'registerTime': this.dataForm.registerTime,
                'openTime': this.dataForm.openTime,
                'policy': this.dataForm.policy,
                'introduction': this.dataForm.introduction,
                'prompt': this.dataForm.prompt,
                'ewmLogo': this.dataForm.ewmLogo,
                'idCardImg1': this.dataForm.idCardImg1,
                'idCardImg2': this.dataForm.idCardImg2,
                'serviceProviderNo': this.dataForm.serviceProviderNo,
                'businessLicense': this.dataForm.businessLicense,
                'other': this.dataForm.other,
                'status': this.dataForm.status,
                'sqTime': this.dataForm.sqTime,
                'bdId': this.dataForm.bdId,
                'yeOpen': this.dataForm.yeOpen,
                'wxOpen': this.dataForm.wxOpen,
                'ddOpen': this.dataForm.ddOpen,
                'lnt': this.dataForm.lnt,
                'lat': this.dataForm.lat,
                'reserveRemind': this.dataForm.reserveRemind,
                'tags': this.dataForm.tags,
                'businessType': this.dataForm.businessType,
                'cuisineStyle': this.dataForm.cuisineStyle,
                'remark': this.dataForm.remark
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
